#ifndef __PROTECT_H
#define __PROTECT_H

#include "sys.h" 

#define ArbPA250TempWarn    (70)		//单个PA温度告警门限 70 75
#define ArbPA250TempErr     (75)        //单个PA温度保护门限(之前告警，则立即保护)
#define TempWarnDelay       (60)        //温度 告警 等待时间

#define ArbPA250CurrWarn	(9)			//单个PA电流告警门限(9)
#define ArbPA250CurrErr     (9.5f)      //单个PA电流保护门限(之前告警，则立即保护)(9.5)
#define CurrWarnDelay       (20)        //电流告警 等待时间

#define ArbPA250CurrBalanceWarn	(3.0f)	//单个PA电流均衡告警门限
#define ArbPA250CurrBalanceErr	(3.5f)	//单个PA电流均衡保护门限

#define AMPTempWarn	(65)					//刀片温度告警门限
#define AMPTempErr	(70)					//刀片温度保护门限(之前告警，则立即保护)

#define AMPCurrWarn		(26)				//刀片电流告警门限
#define AMPCurrErr		(28)				//刀片电流保护门限(之前告警，则立即保护)

#define AMPCurrBalanceWarn	(8)		//刀片电流均衡告警门限（某刀片电流与平均电流差值>n,进入告警状态）(8)

#define AMPReflectWarn (120)	        //单个刀片反射功率告警门限(180)
#define AMPReflectErr	(150)			//单个刀片反射功率保护门限(之前告警，则立即保护)
#define ReflectWarnDelay (5)			//反射功率告警等待时间

#define AMPRfBalanceWarn		(480)	//刀片功率平衡告警门限
#define AMPRfBalanceWarnDelay	(30)	//刀片功率平衡告警等待时间

#define HX6203ReflectWarn (300)	    //整机反射功率告警门限300 320
#define HX6203ReflectErr (320)		//整机反射功率保护门限(之前告警，则立即保护)

#define GainWarn (1000)				    //增益异常功率差值告警门限
#define GainWarnDelay (10)				//增益异常告警延迟

//保护寄存器位定义
#define PA250TempProtectBit     0
#define PA250CurrProtectBit     1
#define AMPTempProtectBit       2
#define AMPCurrProtectBit       3
#define AMPReflectProtectBit    4
#define AMPRfBalanceProtectBit  5
#define HX6203ReflectProtectBit 6
#define HX6203GainProtectBit    7

//生效的保护位
#define ERROR_HAPPEN    (BIT_READ(HX6203_Protect, HX6203ReflectProtectBit)  || \
                        BIT_READ(HX6203_Protect, AMPReflectProtectBit)      || \
                        BIT_READ(HX6203_Protect, PA250TempProtectBit)       || \
                        BIT_READ(HX6203_Protect, AMPTempProtectBit))
						
#define POWER_PROTECT	SELECT_VALUE(P_Protect_Factory, P_Protect_Debug)
#define PROTECT_FLAG	((HX6203.AimRF > POWER_PROTECT) || (HX6203.FwdRF > POWER_PROTECT))

extern unsigned int HX6203_Protect;

void ProtectLogic(void);

#endif
